<!DOCTYPE html>
<html lang="zh-cn">
<head>
  <meta charset="utf-8"/>
  <meta name="viewport" content="width=device-width, initial-scale=1"/>
  <title>{{$domain['domain']}} - 短网址生成器</title>
  <meta name="keywords" content="短网址生成,URL缩短,{{$domain['domain']}}" />
  <meta name="description" content="6r.gs 提供快速、稳定的短网址生成服务，让您的长链接变得更简洁易分享。" />
  <!-- 替换为国内CDN -->
  <link href="/stateuser/bootstrap-5.3.0/css/bootstrap.min.css" rel="stylesheet"/>
  {{-- <link href="https://cdn.staticfile.org/font-awesome/5.15.4/css/all.min.css" rel="stylesheet"/> --}}
  <style>
    body {
      background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
      min-height: 100vh;
      color: #333;
    }
    .navbar {
      background: rgba(255, 255, 255, 0.1);
      backdrop-filter: blur(10px);
      border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    }
    .form-container {
      max-width: 600px;
      margin: 100px auto;
      padding: 40px;
      background: rgba(255, 255, 255, 0.9);
      border-radius: 15px;
      backdrop-filter: blur(10px);
      box-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.37);
      color: #333;
    }
    .form-control {
      background: rgba(255, 255, 255, 0.9);
      border: none;
      color: #333;
    }
    .form-control:focus {
      background: rgba(255, 255, 255, 0.9);
      color: #333;
      box-shadow: none;
    }
    .btn-primary {
      background: #667eea;
      border: none;
      width: 100%;
      padding: 12px;
      margin-top: 20px;
    }
    .btn-primary:hover {
      background: #5a6fd1;
    }
    #shortenedUrlDisplay {
      margin-top: 30px;
    }
    #shortenedUrlDisplay .alert {
      font-size: 1.25rem;
      background-color: #d4edda;
      border-color: #c3e6cb;
    }
    #shortenedUrl {
      font-size: 1.5rem;
      color: #007bff;
      text-decoration: underline;
    }
    .copy-btn {
      margin-left: 10px;
      font-size: 1.25rem;
      color: #28a745;
      cursor: pointer;
    }
    .copy-btn:hover {
      text-decoration: underline;
    }
    .navbar-brand {
      font-weight: bold;
      color: #fff !important;
    }
    .nav-link {
      color: rgba(255, 255, 255, 0.9) !important;
    }
    .nav-link:hover {
      color: #fff !important;
    }
  </style>
  <script src="/stateuser/js/jquery.min.js"></script>
  <script src="/stateuser/bootstrap-5.3.0/js/bootstrap.bundle.min.js"></script>
  <script>
    $(document).ready(function() {
      $('#shortenForm').on('submit', function(e) {
        e.preventDefault();
        $('.btn-primary').prop('disabled', true).html('<i class="fas fa-spinner fa-spin"></i> 生成中...');
        $.ajax({
          url: '/api/dwz/{{$domain['id']}}',
          method: 'POST',
          data: $(this).serialize(),
          headers: {
            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
          },
          success: function(response) {
            $('.btn-primary').prop('disabled', false).html('生成短链接');
            if (response.status === "1") {
              $('#shortenedUrl').attr('href', response.dwz).text(response.dwz); // 设置短链接的 href 和文本
              $('#shortenedUrlDisplay').css('display', 'block'); // 显示短链接板块
            } else {
              alert(response.msg);
            }
          },
          error: function(xhr) {
            $('.btn-primary').prop('disabled', false).html('生成短链接');
            alert('请求失败，请稍后重试');
          }
        });
      });

      // 复制短链接功能
      $(document).on('click', '.copy-btn', function() {
        var shortUrl = $('#shortenedUrl').text();
        var tempInput = document.createElement("input");
        tempInput.value = shortUrl;
        document.body.appendChild(tempInput);
        tempInput.select();
        document.execCommand("copy");
        document.body.removeChild(tempInput);
        alert('短链接已复制到剪贴板！');
      });
    });
  </script>
</head>
<body>
  <nav class="navbar navbar-expand-lg navbar-dark fixed-top">
    <div class="container">
      <a class="navbar-brand" href="/dwz" target="_blank">{{$domain['domain']}}</a>
      <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
        <span class="navbar-toggler-icon"></span>
      </button>
      <div class="collapse navbar-collapse" id="navbarNav">
        <ul class="navbar-nav ms-auto">
          <li class="nav-item">
            <a class="nav-link" href="/"><i class="fas fa-home"></i> 首页</a>
          </li>
          <li class="nav-item">
            <a class="nav-link" href="/dwz"></i> 共享商城</a>
          </li>
          @if (session('user'))
          <li class="nav-item">
            <a class="nav-link" href="/user/"><i class="fas fa-sign-in-user"></i> 用户中心</a>
          </li>
          @else
          <li class="nav-item">
            <a class="nav-link" href="/user/"><i class="fas fa-sign-in-alt"></i> 登录</a>
          </li>
          <li class="nav-item">
            <a class="nav-link" href="/user/register"><i class="fas fa-user-plus"></i> 注册</a>
          </li>
          @endif
        </ul>
      </div>
    </div>
  </nav>
  <div class="container">
    <div class="form-container">
      <h2 class="text-center mb-4">短网址生成器</h2>
      <form id="shortenForm">
        @if(session('user'))
        <input type="hidden" name="api_token" value="{{ session('user')->api_token }}">
        @endif
        <div class="form-group">
          <label for="url">请输入您的长链接</label>
          <input type="url" name="url" id="url" class="form-control" placeholder="例如：http://{{$domain['domain']}}" required>
        </div>
        <button type="submit" class="btn btn-primary">生成短链接</button>
      </form>
      <div id="shortenedUrlDisplay" class="mt-3" style="display:none;">
        <div class="alert alert-success text-center" role="alert">
          <h4 class="alert-heading">短链接生成成功</h4>
          <p>您的短链接：<a id="shortenedUrl" href="#" target="_blank"></a> <span class="copy-btn" title="复制短链接"><i class="fas fa-copy"></i></span></p>
          <p class="mb-0">点击链接即可访问。</p>
        </div>
      </div>
    </div>
  </div>
</body>
</html>